﻿using System;
using System.Collections.Generic;
using System.Text;
using DotNet.Common;
using DotNet.Data.Factory;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
namespace DotNet.Data
{
	public class Tab_NewClassDal
	{
		IDBHelp db = DBHelp.Create();
		 Hashtable htSyn = Hashtable.Synchronized(new Hashtable());
		StringBuilder strSql = new StringBuilder();

		#region 是否存在该记录
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		/// <param name="newClassID">标识列ID</param>
		public bool Exists(int newClassID)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("select count(1) from [Tab_NewClass] where newClassID=@newclassid ");
			htSyn.Add("@newclassid", newClassID);
			return db.IsExists(strSql.ToString(), htSyn);
		}
		#endregion

		#region 得到该表数据列表
		/// <summary>
		/// 得到该表数据列表
		/// </summary>
		public IList<Tab_NewClass> GetModel()
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("Select [newClassID],[newClassName],[newClassDescription] FROM [Tab_NewClass]");
			 return getTab_NewClassBySql(strSql.ToString());
		}
		#endregion

		#region 根据标识列查询实体
		/// <summary>
		/// 根据标识列查询实体
		/// </summary>
		/// <param name="newClassID">标识列ID</param>
		/// <returns></returns>
		public Tab_NewClass GetModel(int newclassid)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("select [newClassID],[newClassName],[newClassDescription] FROM [Tab_NewClass]");
			strSql.Append(" where newClassID=@newclassid ");
			htSyn.Add("@newclassid", newclassid);
			DataTable dt = db.GetDataTable(strSql.ToString(), htSyn);
			Tab_NewClass tab_newclassModel = new Tab_NewClass();
			if (dt.Rows.Count > 0)
			{
				tab_newclassModel.newClassName=dt.Rows[0]["newClassName"].ToString();
				tab_newclassModel.newClassDescription=dt.Rows[0]["newClassDescription"].ToString();				
			}
			return tab_newclassModel;
		}
		#endregion

		#region 修改信息
		/// <summary>
		/// 修改信息
		/// </summary>
		/// <param name="Tab_NewClass">实体</param>
		/// <returns></returns>
		public bool Update(Tab_NewClass tab_newclassModel)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("update [Tab_NewClass] set ");
			strSql.Append("[newClassName]=@newclassname,");
			strSql.Append("[newClassDescription]=@newclassdescription");	
			strSql.Append(" where newClassID=@newclassid ");
			htSyn.Add("@newclassid", tab_newclassModel.newClassID);
			htSyn.Add("@newclassname", tab_newclassModel.newClassName);
			htSyn.Add("@newclassdescription", tab_newclassModel.newClassDescription);		
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 删除信息
		/// <summary>
		/// 删除信息
		/// </summary>
		/// <param name="newClassID">标识列ID</param>
		/// <returns></returns>
		public bool Delete(int newClassID)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("delete from [Tab_NewClass] where newClassID=@newclassid");
			htSyn.Add("newclassid", newClassID);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 添加信息
		/// <summary>
		/// 添加信息
		/// </summary>
		/// <param name="Tab_NewClass">实体</param>
		/// <returns></returns>
		public bool Insert(Tab_NewClass tab_newclassModel)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("insert into [Tab_NewClass]([newClassName],[newClassDescription]) values (@newclassname,@newclassdescription)");
			htSyn.Add("@newclassname", tab_newclassModel.newClassName);
			htSyn.Add("@newclassdescription", tab_newclassModel.newClassDescription);		
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 根据SQL语句获取集合
		/// <summary>
		///根据SQL语句获取集合
		/// </summary>
		/// <param name="strSql">sql语句</param>
		public IList<Tab_NewClass> getTab_NewClassBySql(string strSql)
		{
			IList<Tab_NewClass> list = new List<Tab_NewClass>();
			DataTable dt = db.GetDataTable(strSql);
			if (dt.Rows.Count > 0)
			{
				foreach (DataRow dr in dt.Rows)
				{
					Tab_NewClass tab_newclassModel = new Tab_NewClass();
					tab_newclassModel.newClassID= Convert.ToInt32(dr["newClassID"]);
					tab_newclassModel.newClassName=dr["newClassName"].ToString();
					tab_newclassModel.newClassDescription=dr["newClassDescription"].ToString();			
					list.Add(tab_newclassModel);
				}
			}
			return list;
		}
		#endregion
	}
}
